package com.skyolder.milkbee.web.util;

import java.util.Optional;

import javax.inject.Inject;

import org.springframework.stereotype.Component;

import com.skyolder.milkbee.domain.Leaguer;
import com.skyolder.milkbee.domain.User;
import com.skyolder.milkbee.security.SecurityUtils;
import com.skyolder.milkbee.service.LeaguerService;
import com.skyolder.milkbee.service.UserService;
@Component
public class WebUserUtil {
	@Inject
	private UserService userService;
	@Inject
	private LeaguerService leaguerService;
	public User getCurrentUser(){
		Optional<User> ouser = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin());
		return ouser.get();
	}
	public Leaguer getCurrentLeaguer(){
		Optional<User> ouser = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin());
		if(!ouser.isPresent()){
			return null;
		}
		return leaguerService.findByUser(ouser.get());
	}
	
	public Leaguer getByUserId(Long userId){
		return leaguerService.findOneByUserId(userId);
	}
}
